using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using NHibernate.Data.Managers;
using NHibernate.Data.Models;
using NHibernate.Data.Base;

namespace NHibernate.Data.UnitTests
{
	[TestFixture]
    public partial class OriginCountryTests : UNuitTestBase
    {
        protected IOriginCountryManager manager;
		
		public OriginCountryTests()
        {
            manager = managerFactory.GetOriginCountryManager();
        }
		
		protected OriginCountry CreateNewOriginCountry()
		{
			OriginCountry entity = new OriginCountry();
			
			// You may need to maually enter this key if there is a constraint violation.
			entity.Id = default(Int64);
			
			entity.Introduction = default(Int64);
			entity.Climate = default(Int64);
			entity.LocalName = default(Int64);
			entity.InternationalName = "Test Test ";
			entity.Longitude = 70;
			entity.Latitude = 98;
			
			return entity;
		}
		protected OriginCountry GetFirstOriginCountry()
        {
            IList<OriginCountry> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				OriginCountry entity = CreateNewOriginCountry();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                OriginCountry entityA = CreateNewOriginCountry();
				manager.Save(entityA);

                OriginCountry entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                OriginCountry entityA = GetFirstOriginCountry();
				entityA.Introduction = default(Int64);
				
				manager.Update(entityA);

                OriginCountry entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.Introduction, entityB.Introduction);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                OriginCountry entity = GetFirstOriginCountry();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}